﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    public interface IGroup : IDisposable
    {
        bool IsActive { get; set; }
        short ID { get; }
        int UpdateRate { get; set; }
        float DeadBand { get; set; }
        string Name { get; set; }
        IDriver Parent { get; }
        //IDataServer Server { get; }
        IEnumerable<ITag> Items { get; }
        bool AddItems(IList<TagMetaData> items);
        bool AddTags(IEnumerable<ITag> tags);
        bool RemoveItems(params ITag[] items);
        bool SetActiveState(bool active, params short[] items);
        ITag FindItemByAddress(string addr);
        //HistoryData[] BatchRead(DataSource source, bool isSync, params ITag[] itemArray);
        int BatchWrite(SortedDictionary<ITag, object> items, bool isSync = true);

        ItemData<int> ReadInt32(string address);
        ItemData<uint> ReadUInt32(string address);
        ItemData<short> ReadInt16(string address);
        ItemData<ushort> ReadUInt16(string address);
        ItemData<byte> ReadByte(string address);
        ItemData<float> ReadFloat(string address);
        ItemData<bool> ReadBool(string address);
        ItemData<string> ReadString(string address);

        int WriteInt32(string address, int value);
        int WriteUInt32(string address, uint value);
        int WriteInt16(string address, short value);
        int WriteUInt16(string address, ushort value);
        int WriteFloat(string address, float value);
        int WriteString(string address, string value);
        int WriteBit(string address, bool value);
        int WriteBits(string address, byte value);

        event DataChangeEventHandler DataChange;
    }
    public class DataChangeEventArgs : EventArgs
    {
        //public DataChangeEventArgs(int transactionID, IList<HistoryData> pValues)
        //{
        //    this.TransactionID = transactionID;
        //    this.Values = pValues;
        //}

        //public int TransactionID;
        //public IList<HistoryData> Values;
    }

    public class WriteCompleteEventArgs : EventArgs
    {
        public WriteCompleteEventArgs(int transactionID, short[] pIds, int[] errors)
        {
            this.TransactionID = transactionID;
            this.Values = pIds;
            this.Errors = errors;
        }

        public int TransactionID;
        public short[] Values;
        public int[] Errors;
    }

    public delegate void DataChangeEventHandler(object sender, DataChangeEventArgs e);

    public delegate void ReadCompleteEventHandler(object sender, DataChangeEventArgs e);

    public delegate void WriteCompleteEventHandler(object sender, WriteCompleteEventArgs e);

}
